package com.xuexisheqv.subject.domain.handler.subject;

import com.xuexisheqv.subject.common.enums.IsDeletedFlagEnum;
import com.xuexisheqv.subject.common.enums.SubjectInfoTypeEnum;
import com.xuexisheqv.subject.domain.convert.BriefSubjectConverter;
import com.xuexisheqv.subject.domain.convert.JudgeSubjectConverter;
import com.xuexisheqv.subject.domain.entity.SubjectInfoBO;
import com.xuexisheqv.subject.domain.entity.SubjectOptionBO;
import com.xuexisheqv.subject.infra.basic.entity.SubjectBrief;
import com.xuexisheqv.subject.infra.basic.entity.SubjectJudge;
import com.xuexisheqv.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 简答题目策略类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        // 简答题目的插入
        if(subjectInfoBO == null){
            return;
        }
        SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE.convertBoToEntity(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId().intValue());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefService.batchInsert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(int subjectId) {
        // 创建简答题对象
        SubjectBrief subjectBrief  = new SubjectBrief();
        // 将id设置进去
        subjectBrief.setSubjectId(subjectId);
        // 根据题目 id 找到 数据库中的真正简答题
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        // 将简答题的答案设置到 Bo 里面
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
